package com.zhidou;

import java.io.Serializable;

public class Paddle implements Serializable {
    private static final long serialVersionUID = 4675251348885725046L;
    private int left;
    private int right;

    public int getLeft() {
	return left;
    }

    public void setLeft(int left) {
	this.left = left;
    }

    public int getRight() {
	return right;
    }

    public void setRight(int right) {
	this.right = right;
    }

    public void moveRight() {
	if (right < TileView.mXTileCount - 2) {
	    left += 2;
	    right += 2;
	}
    }

    public void moveLeft() {
	if (left > 1) {
	    left -= 2;
	    right -= 2;
	}
    }

    public Paddle(int length) {
	left = 4;
	right = left + length;
    }

    public boolean checkCollide(Ball ball) {
	if (ball.getY() == TileView.mYTileCount - 1 && ball.getX() >= left && ball.getX() <= right) {
	    ball.turnY();

	    if (ball.getX() - left <= 1) {
		ball.setSpeedX(-2);
	    } else if (right - ball.getX() <= 1) {
		ball.setSpeedX(2);
	    } else {
		ball.setSpeedX(ball.getSpeedX() > 0 ? 1 : -1);
	    }
	    return true;
	}
	return false;
    }
}
